package com.fjut.pojo;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

@Aspect
public class TheLogger {
    private static Logger logger = Logger.getLogger("TheLogger.class");
    @Pointcut("execution(* com.fjut..*.*(..))")
    public void pointCut(){}
    @Before("pointCut()")
    public void before(JoinPoint jp){
        logger.info(jp.getTarget()+"调用"+jp.getSignature().getName()+"方法，传入参数："+jp.getArgs());
    }
    @AfterReturning(pointcut = "pointCut()",returning = "result")
    public void after(JoinPoint jp,Object result){
        logger.info(jp.getTarget()+"调用"+jp.getSignature().getName()+"方法，返回值："+result+"["+result.getClass()+"]");
    }
    @AfterThrowing(pointcut = "pointCut()",throwing = "e")
    public void afterThrowing(JoinPoint jp,RuntimeException e){
        logger.error(jp.getTarget()+"调用"+jp.getSignature().getName()+"方法，抛出错误："+e);
    }
    @After("pointCut()")
    public void finallylogger(JoinPoint jp){
        logger.info(jp.getTarget()+"调用"+jp.getSignature().getName()+"方法，执行结束");
    }
}
